package edu.itstudy.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.itstudy.bean.User;
import edu.itstudy.services.IUserServices;
import edu.itstudy.services.impl.IUserServicesImpl;

public class UserInfoServlet extends HttpServlet {
	
private IUserServices iuserServices = new IUserServicesImpl();
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
		 * 获取用户uid 
		 * 根据uid获取当前用户信息
		 * 在页面显示
		 */
		String uid_ = request.getParameter("uid");
		String flag = request.getParameter("flag");//flag=1 修改 ;flag=0查看
		int uid = 0;
		if(null != uid_&& !"".equals(uid_)) {
			uid = Integer.parseInt(uid_);
		}
		User user = iuserServices.getUserById(uid);
		request.setAttribute("user", user);
		if(null != flag && "1".equals(flag)) {
			request.getRequestDispatcher("/WEB-INF/content/userUpdate.jsp").forward(request, response);
		}else {		
			request.getRequestDispatcher("/WEB-INF/content/userInfo.jsp").forward(request, response);
		}
	}
}
